package com.guomao.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.support.BindingAwareModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.Map;

@SessionAttributes(value = "msg")
//@SessionAttributes(value = {"msg", "msg2"})
@Controller
public class ControllerB {
    @RequestMapping("/method2")
    public String method2(Map<String, Object> map) {
        map.put("msg", "你好啊");
        System.out.println(map.getClass());
        return "index1";
    }


    @RequestMapping("/method3")
    public String method3(Model model) {
        model.addAttribute("msg", "你好棒");
        System.out.println(model.getClass());
        return "index1";
    }

    @RequestMapping("/method4")
    public String method4(ModelMap modelMap, BindingAwareModelMap a) {
        System.out.println(modelMap.getClass());
        modelMap.addAttribute("msg", "你好坏");
        return "index1";
    }

    @RequestMapping("/method5")
    public ModelAndView method5() {
        ModelAndView mv = new ModelAndView("index1");
        mv.addObject("msg", "我是model&view");
        return mv;
    }

    @RequestMapping("/method6")
    public ModelAndView method6() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index1");
        mv.addObject("msg2", "我是model&view2");
        mv.addObject("msg", "我是model&view");
        return mv;
    }


    @RequestMapping("/method7")
    public String method7(HttpSession session) {
        Object msg = session.getAttribute("msg");
        System.out.println(msg);
        return "index1";
    }
}